< previous page page_81 next page >

Page 81
   Res = RasEnumEntries(0, vbNullString, RasEntryBuffer(0), _
   BufferSize, RasEntries)
   If Res = 603 Then
      ' Buffer is too small-Resize to selected size
      RasEntryCount = BufferSize / RasEntrySize
      ReDim RasEntryBuffer(RasEntryCount - 1)
      Res = RasEnumEntries(0, vbNullString, RasEntryBuffer(0), _
      BufferSize, RasEntries)
   End If

   If Res <> 0 Then
      MsgBox "RAS Error #" & Res, vbOKOnly, "Error"
   End If

   For CurrentEntry = 0 To RasEntries - 1
      lstEntries.AddItem RasEntryBuffer(CurrentEntry).szEntryName
   Next CurrentEntry
End Sub
The function has a variable named RasEntrySize, which contains the length of a RASENTRYNAME structure. We start out by creating an array with a single element and initializing its dwSize field to the RasEntrySize value. We then call the RasEnumEntries function, passing the first element of the RasEntryBuffer array, which effectively passes a pointer to the entire array. If the result is 603, we increase the size of the array so that it is large enough to hold all of the entries in the phone book and call the RasEnumEntries function again. On success, we loop through all of the entries in the array and add the names to the list box.
DT looked up at me with a wicked smile. "So you think that will work, do you? Check out the results."
Results
The first thing I noticed was that the RasEnumEntries function returned error 632. The RAS errors can be found in file Raserror.h, part of the Win32 SDK.1 The file contains constant declarations:
#define RASBASE 600

#define ERROR_BUFFER_TOO_SMALL             (RASBASE+3)
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
1 Under Windows95/98, the first call to RasEnumEntries returns error 603, a correct result under the circumstances, suggesting that a larger buffer is needed. The second call returns error 610, indicating that the buffer is invalid (whatever that means).

 
< previous page page_81 next page >